import axios from "axios";
import { ElMessage  } from "element-plus";

axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
// axios.defaults.baseURL = process.env.VUE_APP_API_KEY;
axios.defaults.withCredentials = true;

axios.interceptors.response.use(
  response => {
    // if (response.data.code !== 200) {
    //   return Promise.reject(response.data)
    // }
    return response.data;
  },
  error => {
    if (error.response) {
      let status = error.response.status;
      if (status === 404) {
        ElMessage.warning("接口未找到!");
      } else {
        ElMessage.error("服务器繁忙,请稍后再试!");
      }
      return Promise.reject(error);
    }
    ElMessage.error("未知错误!");
    return Promise.reject(error);
  }
);
